﻿<%@ Page Title="" Language="C#" MasterPageFile="~/member/mMenber.master" AutoEventWireup="true" CodeBehind="ItemInfo.aspx.cs" Inherits="map.member.ItemInfo" %>

<%@ Register Assembly="FredCK.FCKeditorV2" Namespace="FredCK.FCKeditorV2" TagPrefix="FCKeditorV2" %> 
<asp:Content ID="Content1" ContentPlaceHolderID="head2" runat="server">
<style type ="text/css" >
   .itemHeaderDiv
   {
       background:url(../img/upItem.gif) no-repeat;
       padding-left:60px;
       padding-top:10px;
       height:40px;
       vertical-align:middle;
   } 
   .itemHeaderDiv span
   {
       font-size:x-large;
       color:Red;
   }
   .itemBodyFieldSet
   {                        
       width:850px; 
       margin:0px 0px 0px 0px ;
       padding:0px 0px 0px 0px; 
        
   }
   .itemBodyHeaderDiv
   {
       width:100%;
       height:25px;
       background-color:#E4EEFC;
       border-bottom:solid 1px lightGray;
       vertical-align:middle;
       padding-top:5px;
       padding-bottom:5px;
   }
   .itemBodyHeaderDiv span
   {
       font-size:larger;
       font-weight:bold;
   }
   .itemBodyEditTable
   {
       width:100%;
       border:none;
       margin:0px 0px 0px 0px;
       padding:0px 0px 0px 0px;
   }
   .itemBodyEditCateTd
   {
       border-right:solid 1px lightGray;
       width:200px;
       margin:0px 0px 0px 0px ;
       padding:15px 5px 5px 5px;
       vertical-align:top;
   }
   #itemcateUl
   {
       list-style-type:none;
   }
   .itemBodyEditItemTd
   {
       vertical-align:top;
       padding-left:30px;
       padding-top:10px;
   }
   .itemBodyEditItemTdulli
   {
       font-size:large;
       font-weight:bold;
       width:100% ;
       list-style-type:none ;
       
   }
   .itemBodyEditItemTdullitable
   {
       font-size:medium ;
       font-weight:normal ;
       width:100%;
   }
   .itemBodyEditItemTdullitable tr
   {
       padding-top:5px;
       height:25px;
   }
   .editItemBodyLeftTd
   {
       text-align:right ;
       width:80px;
       vertical-align:top;
   }
   .editItemBodyRightTd
   {
       text-align:left ;
       vertical-align:top;
   }
   .mandtorySpan
   {
       color:Red;
       vertical-align:text-bottom ;
   }
   .itemTypeUl
   {
   }
   .itemTypeUl li
   {
       display:inline;
       list-style-type:none ;
       padding-right:10px;
   }
   .itemImgPreviewDiv
   {
       width:80px;
       height:80px;
       border:solid 1px #ECECEC;
   }
   .itemImgPreviewDivNoImg
   {
       width:80px;
       height:80px;
       border:solid 1px #ECECEC;
   }
   #itemImgPreviewSpan
   {
       color:Gray;
       text-align:center ;
       vertical-align:middle;
       width:100%;
       height:100%;
       padding-top:30px;
   }
   .itemImgUploaderDiv
   {
       display:inline ;
   }
   #ItemLocationProvinceSelect,#ItemLocatopnCitySelect
   {
       width:150px;
   }
   #ItemPostFeeUl
   {
   }
   .editItemBodyRightTd li
   {
       list-style-type:none;
       display:inline;
      
   }
   #ItemPostFeeUl li
   {
       display:block;
   }
   #setBuyerPostFeeDiv
   {
       background-color:#ECECEC;
       border:solid 1px lightGray;
       width:450px;
       padding-top:10px;
       padding-left:10px;
       display:none;
   }
   #setBuyerPostFeeDiv input
   {
       width:80px;
   }
   .ErrorMsgP
   {
       border :solid 1px red;
       background-color:#FFF2F2;
       width:150px;       
       margin-top:3px;
   }
   .hiddenButton
   {
       visibility:hidden ;
   }
   .sellerCateListUl
   {
       overflow:scroll ; 
       padding-left:5px; 
       padding-top:10px; 
       width:400px; 
       height:200px; 
       border:solid 1px #ECECEC
   }
   .sellerCateListUl li
   {
       display:block;
       list-style-type :none; 
       padding-left:6px; 
   }
   .sellerCateListUl li label
   {
       padding-left:5px;
   }
   .ChildSellerCate
   {
     text-align:left;
     background:url(../img/cat-sub.png) no-repeat -20px -8px;
     text-indent:25px;
     cursor:pointer;  
   }
   .ParentSellerCate
   {
       cursor:not-allowed;
       color:Gray ;
   }
</style>
<link href="../outstyle.css" rel="stylesheet" type="text/css" />
<script src="../js/dropdowncontent.js" type="text/javascript"></script>
</asp:Content>

<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder3" runat="server">
    <div>
        <div class="itemHeaderDiv">
            <h2><span>发布宝贝</span></h2>
        </div> <br />
        <fieldset class ="itemBodyFieldSet">
            <div class="itemBodyHeaderDiv">
                <table style =" width:100%;">
                    <tr>
                        <td>
                             <img style =" padding-left:10px"  alt="填写宝贝信息" src ="../img/updateitem.gif"/>
                             <span>填写宝贝信息</span>
                        </td>
                        <td style =" text-align:right; padding-right:10px; ">
                            <span style ="color:Red ">*</span>
                            表示该项必填
                        </td>
                    </tr>
                </table>
               
            </div>
            <table class="itemBodyEditTable">
                <tr>                  
                    <td class ="itemBodyEditItemTd">
                        <ul style =" list-style-type:decimal  ">
                            <li class="itemBodyEditItemTdulli">
                                宝贝基本信息<br />
                                <table class ="itemBodyEditItemTdullitable">                                     
                                    <tr>
                                        <td class ="editItemBodyLeftTd" style =" padding-top:5px;">
                                            宝贝类目：
                                        </td>
                                        <td class ="editItemBodyRightTd">
                                            <table style =" width:100%; margin:0px 0px 0px 0px ; padding:0px 0px 0px 0px;">
                                                <tr>
                                                    <td style ="width:5px;">
                                                        <span class ="mandtorySpan" style =" width:5px;">*</span>
                                                    </td>
                                                    <td style ="width:25px;">
                                                        <a id="editCateAnchor"  href ="#">
                                                            <img  style =" border:none" alt="编辑类目" title="编辑类目" src ="../img/edititem.gif"/>
                                                        </a>
                                                    </td>
                                                    <td style ="  margin:0px 0px 0px 0px ;  padding:-10px 0px 0px 0px;">
                                                        <ul id="itemcateUl">
                                                        </ul>
                                                    </td>                                                    
                                                </tr>
                                            </table>
                                        </td>
                                    </tr>
                                    <tr>
                                        <td class ="editItemBodyLeftTd">
                                            宝贝类型：
                                        </td>
                                        <td class ="editItemBodyRightTd">                                             
                                            <span class ="mandtorySpan" style =" display:inline ">*</span>
                                            <ul class ="itemTypeUl"  style =" display:inline ">
                                               <li>
                                                    <input  type ="radio"  checked ="true" id="NewItemRadio" name="itemTypeRadio" value ="new"/><label for ="NewItemRadio">全新</label>
                                               </li>
                                               <li> 
                                                    <input  type ="radio"  id="SecondItemRadio" name ="itemTypeRadio"  value ="second"/> <label for ="SecondItemRadio">二手</label>
                                               </li>
                                               <li>
                                                    <input  type ="radio"  id="UnusedItemRadio"  name ="itemTypeRadio" value ="unused"/> <label for ="UnusedItemRadio">个人闲置</label>
                                               </li>
                                            </ul>                                            
                                        </td>
                                    </tr>
                                    <tr>
                                        <td class ="editItemBodyLeftTd">
                                            宝贝标题：
                                        </td>
                                        <td class ="editItemBodyRightTd">
                                            <span class="mandtorySpan">*</span>
                                            <input  id="itemTitleTextBox" type ="text" maxlength ="60" style =" width:60%"/>
                                            <span style ="color:Gray; font-size:small ">限定在30个汉字内（60个字符） </span>
                                        </td>
                                    </tr>
                                    <tr>
                                        <td class ="editItemBodyLeftTd">
                                            一口价：
                                        </td>
                                        <td class ="editItemBodyRightTd">
                                            <span class="mandtorySpan">*</span>
                                            <input  type ="text" id="itemPriceTextBox"/>元
                                        </td>
                                    </tr>
                                    <tr>
                                        <td class ="editItemBodyLeftTd">
                                            宝贝数量：
                                        </td>
                                        <td class ="editItemBodyRightTd">
                                            <span class ="mandtorySpan">*</span>
                                            <input type ="text" id="itemCountTextBox" value =""/>件
                                        </td>
                                    </tr>
                                    <tr>
                                        <td class ="editItemBodyLeftTd">
                                            宝贝图片：
                                        </td>
                                        <td class ="editItemBodyRightTd" id="editItemBodyRightTd_ItemImg">
                                            <table>
                                                <tr>
                                                    <td>
                                                        <div class ="itemImgPreviewDivNoImg" id="itemImgPreviewDiv">
                                                            <span id="itemImgPreviewSpan" style="display:block " >暂无图片</span>
                                                        </div>
                                                    </td>
                                                    <td style =" padding-left:10px">
                                                        <div class ="itemImgUploaderDiv">
                                                            <iframe id="FileUploadFrame" name="FileUploadFrame" scrolling="no"  style=" overflow:hidden;"  src="../common/UploadFilePage.aspx"  
                                                             frameborder="0" height="30px" width="400px"></iframe>
                                                            <%--<asp:FileUpload ID="itemImgFileUpload" runat="server" />--%>
                                                            <p id="itemImgTipP">图片应小于120k，jpg或gif格式。建议为500x500像素</p>
                                                            <input  type="hidden" id="itemImgPathHidden"/>
                                                        </div> 
                                                    </td>
                                                    <td>
                                                        <div>
                                                            <a href ="#" onclick ="updateItemImg(false);">预览</a>
                                                        </div>
                                                    </td>
                                                </tr>
                                            </table>                                                                                      
                                        </td>
                                    </tr>
                                    <tr>
                                        <td class ="editItemBodyLeftTd">
                                            宝贝描述：
                                        </td>
                                        <td class ="editItemBodyRightTd">
                                            <table>
                                                <tr>
                                                    <td  style =" vertical-align:top">
                                                        <span class ="mandtorySpan">*</span>
                                                    </td>
                                                    <td>
                                                        <FCKeditorV2:FCKeditor ID="ItemDesc_Editor" runat ="server" Height="400px" Width="700px"></FCKeditorV2:FCKeditor>
                                                    </td>
                                                </tr>
                                            </table>
                                        </td>
                                    </tr> 
                                    <tr>
                                        <td class ="editItemBodyLeftTd">
                                            在店铺中所属的分类：
                                        </td>
                                        <td class ="editItemBodyRightTd">
                                            <table>
                                                <tr>
                                                    <td  style =" vertical-align:top">
                                                        <span class ="mandtorySpan">*</span>
                                                    </td>
                                                    <td>
                                                        <%--<div style =" overflow:scroll ; width:400px; height:300px; border:solid 1px #ECECEC">--%>
                                                            <ul class ="sellerCateListUl" id="sellerCateListUl" name="sellerCateListUl" >
                                                                
                                                            </ul>
                                                        <%--</div>--%>
                                                    </td>
                                                </tr>
                                            </table>
                                            
                                        </td>
                                    </tr>                                    
                                </table> <br />
                            </li>
                            <li  class="itemBodyEditItemTdulli">
                                宝贝物流信息<br />
                                <table class ="itemBodyEditItemTdullitable">
                                    <tr>
                                        <td class ="editItemBodyLeftTd">
                                            所在地：
                                        </td>
                                        <td class ="editItemBodyRightTd">
                                            <span class="mandtorySpan">*</span>
                                            <select id="ItemLocationProvinceSelect" onchange ="provinceSelectChanged(this);">
                                                  <option value="">请选择省份</option>
                                            </select>
                                            <select id="ItemLocatopnCitySelect">
                                                  <option value="">请选择城市</option>
                                            </select>
                                        </td>
                                    </tr>
                                    <tr>
                                        <td class ="editItemBodyLeftTd">
                                            运费：
                                        </td>
                                        <td class ="editItemBodyRightTd">
                                            <ul id="ItemPostFeeUl">
                                                <li>
                                                    <input  type="radio" value="seller" id="PostFeeSellerRadio" name ="PostFeeRedio" checked ="true" onclick ="document.getElementById('setBuyerPostFeeDiv').style.display ='none';"/> <label for="PostFeeSellerRadio">卖家承担运费</label>
                                                </li>
                                                <li>
                                                    <input  type="radio"  value="buyer" id="PostFeeBuyerRadio" name ="PostFeeRedio"  onclick ="document.getElementById('setBuyerPostFeeDiv').style.display ='block';"/> <label for="PostFeeBuyerRadio">买家承担运费</label>
                                                </li>
                                            </ul>
                                            <div id="setBuyerPostFeeDiv" >
                                                <label for ="PostFeeTextBox">平邮：</label> <input  type="text" value ="0" id="PostFeeTextBox"/>元 &nbsp;
                                                <label for ="ExpressFeeTextBox">快递：</label> <input  type="text" value ="0" id="ExpressFeeTextBox"/>元 &nbsp;
                                                <label for ="EMSFeeTextBox">EMS：</label> <input  type="text" value ="0" id="EMSFeeTextBox"/>元 &nbsp;
                                            </div>
                                        </td>
                                    </tr>
                                </table><br />
                            </li>
                            <li  class="itemBodyEditItemTdulli">
                                其他信息<br />
                                <table class ="itemBodyEditItemTdullitable">
                                    <tr>
                                        <td class ="editItemBodyLeftTd">
                                            会员打折：
                                        </td>
                                        <td class ="editItemBodyRightTd">
                                            <ul id="ItemMemberDiscountUl">
                                                <li>
                                                    <input  type="radio" value="false" id="hasNotDiscountRadio" name ="MemberDiscountRedio" checked ="true" /> <label for="hasNotDiscountRadio">不参与会员折扣</label>
                                                </li>
                                                <li>
                                                    <input  type="radio"  value="true" id="hasDiscountRadio" name ="MemberDiscountRedio" /> <label for="hasDiscountRadio">参与会员折扣</label>
                                                </li>
                                            </ul>
                                        </td>
                                    </tr>
                                    <tr>
                                        <td class ="editItemBodyLeftTd">
                                            有效期：
                                        </td>
                                        <td class ="editItemBodyRightTd">
                                            <ul id="ItemValidThuUl">
                                                <li>
                                                    <input  type="radio" value="7" id="OneWeekValidThuRadio" name ="ItemValidThuRedio" checked ="true" /> <label for="OneWeekValidThuRadio">7天</label>
                                                </li>
                                                <li >
                                                    <input  type="radio"  value="14" id="TwoWeekValidThuRadio" name ="ItemValidThuRedio" /> <label for="TwoWeekValidThuRadio">14天</label>
                                                </li>
                                            </ul>
                                        </td>
                                    </tr>
                                    <tr>
                                        <td class ="editItemBodyLeftTd">
                                            发票：
                                        </td>
                                        <td class ="editItemBodyRightTd">
                                            <ul id="ItemInvoiceUl">
                                                <li>
                                                    <input  type="radio" value="false" id="HasNoInvoiceRadio" name ="ItemInvoiceRedio" checked ="true" /> <label for="HasNoInvoiceRadio">无</label>
                                                </li>
                                                <li>
                                                    <input  type="radio"  value="true" id="HasInvoiceRadio" name ="ItemInvoiceRedio" /> <label for="HasInvoiceRadio">有</label>
                                                </li>
                                            </ul>
                                        </td>
                                    </tr>
                                    <tr>
                                        <td class ="editItemBodyLeftTd">
                                            保修：
                                        </td>
                                        <td class ="editItemBodyRightTd">
                                            <ul id="ItemWarrantyUl">
                                                <li>
                                                    <input  type="radio" value="false" id="HasNoWarrantyRadio" name ="ItemWarrantyRedio" checked ="true" /> <label for="HasNoWarrantyRadio">无</label>
                                                </li>
                                                <li>
                                                    <input  type="radio"  value="true" id="HasWarrantyRadio" name ="ItemWarrantyRedio" /> <label for="HasWarrantyRadio">有</label>
                                                </li>
                                            </ul>
                                        </td>
                                    </tr>
                                    <tr>
                                        <td class ="editItemBodyLeftTd">
                                            自动重发：
                                        </td>
                                        <td class ="editItemBodyRightTd">
                                            <input  type="checkbox"  id="ItemAutoRepostCheckBox"  checked="true"/> <label for="ItemAutoRepostCheckBox">是</label>
                                        </td>
                                    </tr>
                                    <tr>
                                        <td class ="editItemBodyLeftTd">
                                            橱窗推荐：
                                        </td>
                                        <td class ="editItemBodyRightTd">
                                            <input  type="checkbox"  id="ItemShowCaseCheckbox"  checked="true"/> <label for="ItemShowCaseCheckbox">是</label>
                                        </td>
                                    </tr>
                                </table><br />
                            </li>
                        </ul>
                        <br />
                        <div style =" width:100%; text-align:center;">
                            <input id="UpdateItemButton" value="发布" type="button"  style =" font-size:medium ; font-weight :bold; width:80px ; height:30px"
                                 onclick ="updateItemImg(true);"  />
                        </div>
                        <br />
                    </td>
                </tr>
            </table>
        </fieldset>
    </div>
    
    <script type ="text/javascript" >
        PageUtil =window.PageUtil || {};
        PageUtil = {
            itemImgPath: '',
            itemcid: '',
            itemiid: '',
            itemdesc: '',
            isNew: false,
            hasImgPathError: false,
            allStateArray: [],
            getQueryString: function(queryName) {
                var queryValue = "";
                var queryFound = false;
                if (window.location.search != "") {
                    var search = window.location.search;
                    var i = 0;
                    while (i <= search.length) {
                        start = i;
                        end = start + queryName.length;
                        if (search.substring(start, end) == queryName) {
                            queryFound = true;
                            break;
                        }
                        i++;
                    }
                    if (queryFound) {
                        start = end + 1;
                        end = search.indexOf("&", start);
                        if (end < start)
                            end = search.length;
                        var getvalue = search.substring(start, end);
                        return unescape(getvalue);
                    }
                }
                return queryValue;
            },
            init: function() {
                MyFckEditor.init();

                this.initLocationSelect();

                var ParamsOk = false;
                var cateIds = this.getQueryString("cate");
                var infotype = this.getQueryString("type"); //"edit"; //
                var itemid = this.getQueryString("id"); //"a5fc77bc6c841afb68cd726217e374f7"; //

                if (cateIds != "" && infotype == "new") {
                    this.isNew = true;
                    document.title = "发布宝贝";
                    document.getElementById("UpdateItemButton").value = "发布";
                    this.initByCateIds(cateIds);
                    ParamsOk = true;
                }

                if (infotype == "edit" && itemid != "") {
                    this.isNew = false;
                    document.title = "修改宝贝";
                    document.getElementById("UpdateItemButton").value = "保存";
                    this.initByItemiid(itemid);
                    this.initByCateIds(cateIds, itemid);
                    ParamsOk = true;
                }
                if (ParamsOk == false) {
                    alert("对不起，参数错误！");
                    window.location.href = "publishError.aspx";
                }
            },

            //新建宝贝
            initByCateIds: function(cateIds, itemid) {
                if (cateIds != "") {
                    this.initSellerCateList(cateIds);
                    var editcateanchor = document.getElementById("editCateAnchor");
                    if (arguments.length == 2 && itemid != null) {
                        editcateanchor.href = "ItemCate.aspx?type=edit&cate=" + cateIds + "&id=" + itemid;
                    }
                    else if (arguments.length == 1) {
                        editcateanchor.href = "ItemCate.aspx?type=new&cate=" + cateIds;
                    }
                    var cateidArgs = cateIds.split("_");
                    if (cateidArgs.length != null && cateidArgs.length > 0)
                        this.itemcid = cateidArgs[cateidArgs.length - 1];

                    var itemcateul = document.getElementById("itemcateUl");
                    itemcateul.innerHTML = "";
                    var cateNamesStr = AjaxFunction.GetCateNameListFromIds(cateIds).value;
                    var cateNameArray = eval(cateNamesStr);
                    if (cateNameArray != null && cateNameArray.length > 0) {
                        var hmtl = "";
                        for (var i = 0; i < cateNameArray.length; i++) {
                            hmtl += cateNameArray[i].Name;
                            if (i < cateNameArray.length - 1)
                                hmtl += ">>";
                        }
                        var newLiEle = document.createElement("li");
                        newLiEle.innerHTML = hmtl
                        itemcateul.appendChild(newLiEle);
                    }
                }
            },

            //修改宝贝
            initByItemiid: function(itemid) {
                var result = AjaxFunction.GetItemInfo(itemid);
                if (result.value != null && result.value != "") {
                    var item = eval("(" + result.value + ")");
                    //初始化 宝贝类目

                    this.initSellerCateList(item.seller_cids);
                    var editcateanchor = document.getElementById("editCateAnchor");
                    var itemcateul = document.getElementById("itemcateUl");
                    itemcateul.innerHTML = "";

                    if (item.cIdNames != null && item.cIdNames.ids != null) {
                        var cidsStr = "";
                        for (var i = 0; i < item.cIdNames.ids.length; i++) {
                            if (i > 0)
                                cidsStr += "_";
                            cidsStr += item.cIdNames.ids[i];
                        }
                        editcateanchor.href = "ItemCate.aspx?cate=" + cidsStr;
                        var cateIdNameArray = item.cIdNames;
                        var hmtl = "";
                        for (var i = 0; i < cateIdNameArray.names.length; i++) {
                            hmtl += cateIdNameArray.names[i];
                            if (i < cateIdNameArray.names.length - 1)
                                hmtl += ">>";
                        }
                        var newLiEle = document.createElement("li");
                        newLiEle.innerHTML = hmtl
                        itemcateul.appendChild(newLiEle);
                    }
                    else {
                        editcateanchor.href = "ItemCate.aspx?cate=";
                    }
                    editcateanchor.href += "&type=edit&id=" + item.itemid;

                    this.itemcid = item.itemcid;
                    this.itemiid = item.itemid;
                    this.itemdesc = item.desc;
                    this.setRadioCheckedValue('itemTypeRadio', item.type);
                    this.setTextInputValue('itemTitleTextBox', item.title);
                    this.setTextInputValue('itemPriceTextBox', item.price);
                    this.setTextInputValue('itemCountTextBox', item.count);


                    this.setitemImg(item.imgPath);


                    this.setSelectValue('ItemLocationProvinceSelect', item.state);
                    provinceSelectChanged(document.getElementById('ItemLocationProvinceSelect'));

                    this.setSelectValue('ItemLocatopnCitySelect', item.city);
                    this.setRadioCheckedValue('PostFeeRedio', item.feePayer);


                    this.setTextInputValue('PostFeeTextBox', item.postfee);
                    this.setTextInputValue('ExpressFeeTextBox', item.expressfee);
                    this.setTextInputValue('EMSFeeTextBox', item.emsfee);
                    this.setRadioCheckedValue('MemberDiscountRedio', item.hasdiscount);
                    this.setRadioCheckedValue('ItemValidThuRedio', item.validthu);
                    this.setRadioCheckedValue('ItemInvoiceRedio', item.hasinvoice);
                    this.setRadioCheckedValue('ItemWarrantyRedio', item.haswarranty);
                    this.setCheckInputValue('ItemAutoRepostCheckBox', item.autoRepost);
                    this.setCheckInputValue('ItemShowCaseCheckbox', item.showcase);

                    //this.item = item;
                }
            },
            //店铺自定义商品分类
            initSellerCateList: function(sellerCids) {
                var sellerCateListUl = document.getElementById("sellerCateListUl");
                sellerCateListUl.innerHTML = "";
                var currentSellerCateListResutlt = AjaxFunction.GetUserSellerCateList("");
                if (currentSellerCateListResutlt.value != null && currentSellerCateListResutlt.value != "") {
                    var currentSellerCateList = eval(currentSellerCateListResutlt.value);
                    var ulHtml = "";
                    for (var i = 0; i < currentSellerCateList.length; i++) {
                        var checkDisabledStr = ""; var classStr = ""; var checkedStr = "";
                        if (currentSellerCateList[i].childCids.length > 0) {
                            checkDisabledStr = ' disabled="true" ';
                            classStr = ' class="ParentSellerCate" ';
                        }
                        else {
                            if (sellerCids != "" && (sellerCids.indexOf(currentSellerCateList[i].cid) >= 0)) {
                                checkedStr = ' checked="true" ';
                            }
                        }
                        ulHtml += '<li ' + classStr + '><input ' + checkDisabledStr + checkedStr + ' id="' + currentSellerCateList[i].cid + '" type="checkbox"/><label for="' + currentSellerCateList[i].cid + '">' + currentSellerCateList[i].name + '</label></li>';
                        if (currentSellerCateList[i].childCids != null) {
                            for (var j = 0; j < currentSellerCateList[i].childCids.length; j++) {
                                var childcheckedStr = "";
                                if (sellerCids != "" && (sellerCids.indexOf(currentSellerCateList[i].childCids[j].cid) >= 0)) {
                                    childcheckedStr = ' checked="true" ';
                                }
                                ulHtml += '<li class="ChildSellerCate"><input ' + childcheckedStr + ' id="' + currentSellerCateList[i].childCids[j].cid + '" type="checkbox"/><label for="' + currentSellerCateList[i].childCids[j].cid + '">' + currentSellerCateList[i].childCids[j].name + '</label></li>';
                            }
                        }
                    }
                    sellerCateListUl.innerHTML = ulHtml;
                }
            },
            getSellerCatesStr: function() {
                var sellerCateStr = "";
                var sellerCateListUl = document.getElementById("sellerCateListUl");
                var liEleList = sellerCateListUl.getElementsByTagName("li");
                for (var i = 0; i < liEleList.length; i++) {
                    var inputEle = liEleList[i].getElementsByTagName("input")[0];
                    if (inputEle.checked == true)
                        sellerCateStr += "," + inputEle.id;
                }
                sellerCateStr += ",";
                return sellerCateStr;
            },
            //初始化城市地址信息
            initLocationSelect: function() {
                var allStatesStr = AjaxFunction.GetAllStates().value;
                if (allStatesStr != null && allStatesStr != "") {
                    this.allStateArray = eval(allStatesStr);
                    var provinceselect = document.getElementById("ItemLocationProvinceSelect");
                    provinceselect.innerHTML = "";
                    var newOptionEle = document.createElement("option");
                    newOptionEle.value = "";
                    newOptionEle.innerHTML = "请选择省份";
                    provinceselect.appendChild(newOptionEle);
                    if (this.allStateArray.length != null && this.allStateArray.length > 0) {
                        for (var i = 0; i < this.allStateArray.length; i++) {
                            newOptionEle = document.createElement("option");
                            newOptionEle.value = this.allStateArray[i].state;
                            newOptionEle.innerHTML = this.allStateArray[i].state;
                            provinceselect.appendChild(newOptionEle);
                        }
                    }
                }
            },

            getRadioCheckedValue: function(radioName) {
                var radioNameEle = document.getElementsByName(radioName);
                for (var i = 0; i < radioNameEle.length; i++) {
                    if (radioNameEle[i].checked == true)
                        return radioNameEle[i].value;
                }
                return "";
            },

            getTextInputValue: function(id) {
                return document.getElementById(id).value;
            },

            getSelectValue: function(id) {
                var selectEle = document.getElementById(id);
                return selectEle[selectEle.selectedIndex].value;
            },

            getCheckInputValue: function(id) {
                return document.getElementById(id).checked;
            },

            setRadioCheckedValue: function(radioName, value) {
                var radioNameEle = document.getElementsByName(radioName);
                var found = false;
                for (var i = 0; i < radioNameEle.length; i++) {
                    radioNameEle[i].checked = (radioNameEle[i].value == value);
                    if (radioNameEle[i].value == value) {
                        found = true;
                        radioNameEle[i].click();
                    }
                }
                if (found == false && radioNameEle.length > 0) {
                    radioNameEle[0].checked = true;
                    radioNameEle[0].click();
                }
            },

            setTextInputValue: function(id, value) {
                document.getElementById(id).value = value;
            },

            setSelectValue: function(id, value) {
                var selectEle = document.getElementById(id);
                var found = false;
                for (var i = 0; i < selectEle.length; i++) {
                    selectEle[i].selected = (selectEle[i].value == value);
                    if (selectEle[i].value == value)
                        found = true;
                }
                if (found == false && selectEle.length > 0) {
                    selectEle[0].selected = true;
                }
            },

            setCheckInputValue: function(id, value) {
                if (typeof value != "Boolean")
                    value = Boolean.parse(value.toString());
                if (value != true)
                    value = false;
                document.getElementById(id).checked = value;
            },

            setitemImg: function(imgPath) {
                var itemImgPathhidden = document.getElementById('itemImgPathHidden');
                var itemImgPreviewdiv = document.getElementById('itemImgPreviewDiv');
                var itemImgPreviewspan = document.getElementById('itemImgPreviewSpan');


                if (imgPath != "") {
                    this.itemImgPath = imgPath;
                    itemImgPathhidden.value = imgPath;
                    var oldImgList = itemImgPreviewdiv.getElementsByTagName("img");
                    var length = oldImgList.length;
                    for (var i = 0; i < length; i++) {
                        itemImgPreviewdiv.removeChild(oldImgList[i]);
                    }
                    itemImgPreviewspan.style.display = "none";
                    var newImgEle = document.createElement("img");
                    newImgEle.src = imgPath;
                    newImgEle.style.width = (itemImgPreviewdiv.offsetWidth - 2) + "px";
                    newImgEle.style.height = (itemImgPreviewdiv.offsetHeight - 2) + "px";
                    itemImgPreviewdiv.appendChild(newImgEle);
                }
                if (itemImgPathhidden.value == "")
                    itemImgPreviewspan.style.display = "block";

            }
        };

       

        MyFckEditor = window.MyFckEditor || {};
        MyFckEditor = {
            InstanceName: 'ctl00_ctl00_ContentPlaceHolder1_ContentPlaceHolder3_ItemDesc_Editor',
            editor: null,
            editorAPI: null,
            //只有当所有加载完成后才能调用成功，否则  FCKeditorAPI 为空
            init: function() {
                if (this.editorAPI == null)
                    this.editorAPI = FCKeditorAPI;
                if (this.editor == null)
                    this.editor = this.editorAPI.GetInstance(this.InstanceName);
            },
            getHTML: function() {
                return this.editor.GetXHTML(true);
            },
            getText: function() {
                return this.editor.EditorDocument.body.innerText;
            },
            htmlIsNull: function() {
                var html = this.getHTML();
                return html == "";
            },
            setHTML: function(html,reset) {
                this.editor.SetHTML(html,reset);
            }
        };
        
        PageValidate = window.PageValidate || {};
        PageValidate = {
            validateObjArray: [['itemTitleTextBox', '宝贝标题不能为空', 'text'], ['itemPriceTextBox', '宝贝价格应该为有效价格', 'float'], ['itemCountTextBox', '宝贝数量应该为正整数', 'int'],
                           ['ItemLocationProvinceSelect', '请填写宝贝所在省份', 'select'], ['ItemLocatopnCitySelect', '请填写宝贝所在城市', 'select'],
                           [MyFckEditor.InstanceName, '宝贝描述不能为空', 'editor'],
                           ['PostFeeTextBox', '平邮费用应该为有效值', 'fee'], ['ExpressFeeTextBox', '快递费用应该为有效值', 'fee'], ['EMSFeeTextBox', 'EMS费用应该为有效值', 'fee']],
            validateFunc: function(objId) {
                var errorMsg = "";
                var found = false;
                var objCate = "";
                var thisObj;
                for (var i = 0; i < this.validateObjArray.length; i++) {
                    if (this.validateObjArray[i][0] == objId) {
                        found = true;
                        objCate = this.validateObjArray[i][2];
                        thisObj = document.getElementById(objId);
                        switch (this.validateObjArray[i][2]) {
                            case 'text':
                                {
                                    var value = thisObj.value;
                                    var replacedValue = value;
                                    while (replacedValue.indexOf(' ') >= 0) {
                                        replacedValue = replacedValue.replace(/ /, '');
                                    }
                                    errorMsg = (replacedValue == "") ? this.validateObjArray[i][1] : "";
                                    break;
                                }
                            case 'float':
                                {
                                    var value = thisObj.value;
                                    var num = parseFloat(value);
                                    errorMsg = (num.toString().toUpperCase() == 'NAN' || num <= 0) ? this.validateObjArray[i][1] : "";
                                    break;
                                }
                            case 'int':
                                {
                                    var value = thisObj.value;
                                    var num = parseInt(value);
                                    errorMsg = (num.toString().toUpperCase() == 'NAN' || num <= 0) ? this.validateObjArray[i][1] : "";
                                    break;
                                }
                            case 'select':
                                {
                                    var value = thisObj[thisObj.selectedIndex].value;
                                    errorMsg = (value == "") ? this.validateObjArray[i][1] : "";
                                    break;
                                }
                            case 'editor':
                                {
                                    thisObj = thisObj.parentNode;
                                    MyFckEditor.init();
                                    //PageUtil.itemdesc = MyFckEditor.getHTML();
                                    errorMsg = (MyFckEditor.htmlIsNull() == true) ? this.validateObjArray[i][1] : "";
                                    break;
                                }
                            case 'fee':
                                {
                                    var value = thisObj.value;
                                    var num = parseFloat(value);
                                    errorMsg = (num.toString().toUpperCase() == 'NAN' || num < 0) ? this.validateObjArray[i][1] : "";

                                    break;
                                }
                        }
                        break;
                    }
                }
                var pList = thisObj.parentNode.getElementsByTagName("p");
                var hasErrorMsgP = false;
                for (var i = 0; i < pList.length; i++) {
                    if ((pList[i].id == objId + "ErrorMsgP") && pList[i].className == "ErrorMsgP") {
                        hasErrorMsgP = true;
                        break;
                    }
                }
                if (found == true && errorMsg != "") {
                    if (hasErrorMsgP == false) {
                        if (objCate == 'fee') {
                            if (thisObj.parentNode.style.display == 'none')
                                return "";
                        }
                        var newPEle = document.createElement("p");
                        newPEle.className = "ErrorMsgP";
                        newPEle.innerHTML = errorMsg;
                        newPEle.id = objId + "ErrorMsgP";
                        thisObj.parentNode.appendChild(newPEle);
                    }
                }
                if (found == true && errorMsg == "" && hasErrorMsgP == true) {
                    thisObj.parentNode.removeChild(pList[i]);
                }
                return errorMsg;
            },

            validate: function() {
                var errorMsgArray = new Array();
                for (var i = 0; i < this.validateObjArray.length; i++) {
                    var errorMsg = this.validateFunc(this.validateObjArray[i][0]);
                    if (errorMsg != "")
                        errorMsgArray.push(errorMsg);
                }
                return errorMsgArray;
            }
        };

        
        
        
        function provinceSelectChanged(thisObj) {
            var selectedState = thisObj[thisObj.selectedIndex].value;
            var citysSelect = document.getElementById("ItemLocatopnCitySelect");
            citysSelect.innerHTML = "";
            var newOptionEle = document.createElement("option");
            newOptionEle.value = "";
            newOptionEle.innerHTML = "请选择城市";
            citysSelect.appendChild(newOptionEle);
            
            if (selectedState != "" && selectedState != null) {
                var allCitysStr = AjaxFunction.GetAllCitys(selectedState).value;
                var allCityArray = eval(allCitysStr);
                if (allCityArray.length != null && allCityArray.length > 0) {
                    for (var i = 0; i < allCityArray.length; i++) {
                        newOptionEle = document.createElement("option");
                        newOptionEle.value = allCityArray[i].city;
                        newOptionEle.innerHTML = allCityArray[i].city;
                        citysSelect.appendChild(newOptionEle );     
                    }
                }
            }

        }

        var timeid;
        function updateItemImg(isUpdateItem) {
            //PageValidate.validate(); PageUtil.uploadFile();
            var imgPath = "";
            var uploadFileFrame = window.frames["FileUploadFrame"];              
            uploadFileFrame.window.saveFile();
            timeid = setInterval(function() {
                var status = uploadFileFrame.window.getUploadFileStatus();
                if (status == "1") {
                    //alert(imgPath);
                    clearInterval(timeid);
                    imgPath = uploadFileFrame.window.getHttpFileUrl();
                    PageUtil.setitemImg(imgPath);
                    var uploadFileErrorMsg = uploadFileFrame.window.getErrorMsg();
                    var fileName = uploadFileFrame.window.getFileName(); 
                    var frameParentEle = document.getElementById("editItemBodyRightTd_ItemImg");
                    var pEleList = frameParentEle.getElementsByTagName("p");
                    var oldHasErrorMsg = false;
                    var oldIndex = -1;
                    for (var i = 0; i < pEleList.length; i++) {
                        if (pEleList[i].className == "ErrorMsgP") {
                            oldHasErrorMsg = true;
                            oldIndex = i;
                            break;
                        }
                    }
                    PageUtil.hasImgPathError = (uploadFileErrorMsg != "");
                    
                    if (oldHasErrorMsg == true) {
                        if (uploadFileErrorMsg == "") {
                            frameParentEle.removeChild(pEleList[oldIndex]);
                        }
                        else {
                            if (pEleList[oldIndex].innerHTML != uploadFileErrorMsg)
                                pEleList[oldIndex].innerHTML = uploadFileErrorMsg;
                        }
                    }
                    else {
                        if (uploadFileErrorMsg != "") {
                            var newPEle = document.createElement("p");
                            newPEle.className = "ErrorMsgP";
                            newPEle.style.width = "250px";
                            newPEle.innerHTML = uploadFileErrorMsg+ ((fileName !="") ?("<br/>您的文件名："+ fileName):"") ;
                            frameParentEle.appendChild(newPEle);
                        }
                    }
                    if (isUpdateItem==true )
                        updateItem();
                    return;
                }
            }, 100);
            return;
        }
        function updateItem(){
            var errorMsgArray = PageValidate.validate();
            if (errorMsgArray.length != 0 || PageUtil.hasImgPathError ==true ) {
            }
            else {
                var imgPath = PageUtil.itemImgPath;
                
                var type = PageUtil.getRadioCheckedValue('itemTypeRadio');
                var title = PageUtil.getTextInputValue('itemTitleTextBox');
                var price = parseFloat(PageUtil.getTextInputValue('itemPriceTextBox'));
                var count = parseInt(PageUtil.getTextInputValue('itemCountTextBox'));
                //var imgPath = PageUtil.getTextInputValue('itemImgPathHidden');
                var desc = MyFckEditor.getHTML();  //PageUtil.itemdesc;
                var state = PageUtil.getSelectValue('ItemLocationProvinceSelect');
                var city = PageUtil.getSelectValue('ItemLocatopnCitySelect');
                var feePayer = PageUtil.getRadioCheckedValue('PostFeeRedio');
                var postfee = parseFloat(PageUtil.getTextInputValue('PostFeeTextBox'));
                var expressfee = parseFloat(PageUtil.getTextInputValue('ExpressFeeTextBox'));
                var emsfee = parseFloat(PageUtil.getTextInputValue('EMSFeeTextBox'));
                var hasdiscount = PageUtil.getRadioCheckedValue('MemberDiscountRedio');
                var validthu = parseInt(PageUtil.getRadioCheckedValue('ItemValidThuRedio'));
                var hasinvoice = PageUtil.getRadioCheckedValue('ItemInvoiceRedio');
                var haswarranty = PageUtil.getRadioCheckedValue('ItemWarrantyRedio');
                var autoRepost = PageUtil.getCheckInputValue('ItemAutoRepostCheckBox').toString();
                var showcase = PageUtil.getCheckInputValue('ItemShowCaseCheckbox').toString();
                var seller_cids = PageUtil.getSellerCatesStr();
                var result =  AjaxFunction.UpdateItem(PageUtil.isNew ,PageUtil.itemiid ,PageUtil.itemcid ,type ,title,price ,count,
                    imgPath,desc,state,city,feePayer,postfee,expressfee,emsfee,hasdiscount,validthu,hasinvoice ,haswarranty,
                    autoRepost, showcase, seller_cids);
                if (result.value == true) {
                    window.location.href = "publishResult.aspx";
                }
                else { 
                }
            }
        }

        window.onload = function() { PageUtil.init(); }
        //fkceditor 初始化
        function  FCKeditor_OnComplete() {
            MyFckEditor.init();
            MyFckEditor.setHTML(PageUtil.itemdesc,false );
        }
    </script>
</asp:Content>
